// 121.买卖股票的最佳时机
package LeetcodeHot100;

public class Solution121 {
    public int maxProfit(int[] prices) {
        int maxProfit = Integer.MIN_VALUE;
        int buy = Integer.MAX_VALUE;

        for (int i = 0; i < prices.length; i++) {
            buy = Math.min(buy, prices[i]);
            maxProfit = Math.max(maxProfit, prices[i] - buy);
        }

        return maxProfit;
    }
}
